<?php
class Student extends CI_Controller {
     
	  function __construct()
	{
		parent::__construct();	
	    $this->load->model('student_model');
		$this->load->model('form_model');
		$this->load->model('payment_model');
		
	}
	function getPath($action = '')
	{
		return array('controller' => strtolower(__CLASS__), 'action' => strtolower($action));
	}
	function index($page = 0)
	{
		
		$per_page_count 	     = $this->config->item('per_page_count');
		$view 				     = $this->getPath(__FUNCTION__);
		$view['menu_var']         = 3;
		if(isset($_POST['search']))
		{
			$course              = $this->input->post('course');         // filter subject with course 
			$view['filter1']     = $course ;  
			$this->session->set_userdata(array('filter' => $course));    // set filter value
			
		}
		else
		{
			$view['filter1']     = $this->session->userdata('filter');
		}
		if(!empty($view['filter1']))
		{
		$like['name']             = $view['filter1'];   //$course;
		}
		$where                    = array('users.deleted' => 0);
		$students                 = $this->student_model->getStudents($page, $per_page_count , $like, $where );
		$view['students'] 		  = $students->records;
		$view['cur_page'] 	      = $page;
		$view['title']		      = 'Users Listing';
		$view['subtitle']	      = 'Users Lists';
		/************************ Pagination block ***********************************/
		$config['base_url'] 	  = $this->config->item('admin_base_url').'/student/index/';
		$config['total_rows'] 	  = $students->total;
		$config['per_page']       = $per_page_count;
		$config['cur_page']       = $page /$per_page_count;
		$config['uri_segment'] 	  = 4;
		$config['num_links'] 	  = 3;
		$this->pagination->initialize($config);
		$view['msg'] 	          = $this->lang->line($this->session->flashdata('users_msg'));
		$this->layout->adminview('students_view', $view);
	
	}
	
	function payment($id='')
	{
		$view['title']	          = 'My Payments';
		$view['subtitle']	      = 'Payments';
		$view['menu_var']         = 4;
		//$mylogin        = $this->session->userdata('mylogin');
		$where                    = array('users.id'=>$id,'users.deleted' => 0);
		$students                 = $this->student_model->getStudents($page, $per_page_count , $like, $where );
		$view['student'] 		  = $students->records[0];
		$form                     = $this->form_model->getForms(0,1,'',array('id'=>$view['student']['country_id']));
		$view['form']             = $form->records[0];
	    $payments                 = $this->payment_model->getPayments(0,'','',array('user_id'=>$id));
		$view['payments']         = $payments->records;
		$save                     = $this->input->post('save');
		if(!empty($save))
		{
			$data                 = $this->retrieve->post($this->payment_model->fields);
			$insertStatus         = $this->payment_model->add($data);
			switch($insertStatus->status)
			{
				case 1:
					$this->session->set_flashdata('users_msg', 'payment_add_success');
					/*if(!empty($cur_page)) 
						redirect($this->config->item('member_base').'student/payment/'.$cur_page,'location');
					else
						redirect($this->config->item('member_base').'student/payment/','location');
					exit;		*/
					break;
				case -1:
					break;
				case -2:
					$view['msg'] 	= $this->lang->line('form_valid_failed');
					break;
				case -3:
					$view['msg'] 	= $this->lang->line('form_already_exists');
					break;
				case false:
					$view['msg'] 	= $this->lang->line('form_add_failure');
	
					break;
				
				default:
					$view['msg'] 	= $this->lang->line('form_add_failure');
					break;
			}
		}
		$this->layout->adminview('payment', $view);
	}
	
	function payments($page=0)
	{
		$per_page_count 	     = $this->config->item('per_page_count');
		$view['title']	          = 'Payments';
		$view['subtitle']	      = 'Payments';
		$view['menu_var']         = 4;
		$payments                 = $this->payment_model->getPayments($page,$per_page_count,'');
		$view['payments']         = $payments->records;
		
		/************************ Pagination block ***********************************/
		$config['base_url'] 	  = $this->config->item('admin_base_url').'/student/payments/';
		$config['total_rows'] 	  = $payments->total;
		$config['per_page']       = $per_page_count;
		$config['cur_page']       = $page /$per_page_count;
		$config['uri_segment'] 	  = 4;
		$config['num_links'] 	  = 3;
		$this->pagination->initialize($config);
		
		$this->layout->adminview('payments', $view);
		
	}
	function bank()
	{
	$view['title']            = "Account details";
	$view['subtitle']         = "Account details";
	$view['menu_var']         = 4;
	$this->layout->adminview('bank', $view);	
	}
	function info($id='')
	{
		$where                    = array('users.id' => $id);
		$students                 = $this->student_model->getStudents($page, $per_page_count , $like, $where );
		$view['students'] 		  = $students->records;
		$view['img']              = $this->config->item('admin_image_path');
		$this->load->view('admin/stu_info', $view);
	}

	function delete($id = '', $cur_page)
	{
		if(empty($id)) 
		{
			redirect($this->config->item('admin_base_url').'registration/index/'.$cur_page,'location');
			exit;
		} 
		else 
		{
			$deleteStatus = $this->student_model->delete($id);
			switch($deleteStatus)
			{
				case 1:
					$this->session->set_flashdata('users_msg', 'student_delete_success');
					redirect($this->config->item('admin_base').'student/index/'.$cur_page,'location');
					exit;		
					break;
				case false:
					$view['msg'] 	    = $this->lang->line('course_delete_failure');
					break;
			}
		}
		
	}
	
	
	
}
?>